package Collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class CollectionDemo5 {
    public static void main(String[] args) {
        Collection<Student>list= new ArrayList<>();
        Student s1 = new Student("张三",18);
        Student s2 = new Student("李四",25);
        Student s3 = new Student("王五",38);
        list.add(s1);
        list.add(s2);
        list.add(s3);
        //迭代器方法遍历
        Iterator<Student>it = list.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }

        System.out.println("---------");

        //增强for
        for (Student student : list) {
            System.out.println(student);
        }
    }
}
